<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * 系统信息插件
 */
namespace Addon\SystemInfo\Controller;
use Addon\SystemInfo\Controller\CommonController;

/**
 * 系统信息插件 
 */
class SystemController extends CommonController{
	
	/**
	 * 系统信息 
	 */
	public function Info(){
		
		
		action_log('addon_systeminfo_system_info'); 
		
	
		//页面配置
			$page = array(
				
				'title'=>'系统信息',
				'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'author'=>'YiPHP',
				'robots' => 'all',
			
			);
			
			$this->assign('page',$page);
			
		$data = S('data');
		
		if(!$data){
			
			//web服务器
			$data['web_server'] = $_SERVER["SERVER_SOFTWARE"];
			//web服务器
			$data['web_system'] = php_uname('s');
			//PHP版本
			$data['php_version'] = PHP_VERSION;
			//mysql版本
			$data['mysql_version'] = $this->_mysql_version();
			//服务器IP
			$data['web_ip'] = GetHostByName($_SERVER['SERVER_NAME']);
			//服务器端口
			$data['web_port'] = $_SERVER['SERVER_PORT'];
			//当前网址
			$data['web_domain'] = $_SERVER['SERVER_NAME'];
			//服务器语言
			$data['web_server_language'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
			//是否可以远程文件获取
			$data['allow_url_fopen'] = ini_get("allow_url_fopen") ? "支持" : "不支持";
			//最大上传限制
			$data['upload_max_filesize'] = ini_get("file_uploads") ? ini_get("upload_max_filesize") : "Disabled";
			//最大执行时间
			$data['max_execution_time'] = ini_get("max_execution_time")."秒";
			//获取服务器时间，中国大陆采用的是东八区的时间,设置时区写成Etc/GMT-8
			date_default_timezone_set("Etc/GMT-8");
			$data['system_time'] = date("Y-m-d H:i:s",time());
			//获得TP版本
			$data['think_version'] = THINK_VERSION;
			//获得YP版本			 
			$data['yiphp_version'] = C('YIPHP_VERSION');
			
			//缓存数据信息2个小时
			S('data',$data,7200);
			
			
			
	
		}
		
			$url  = 'http://api.yiphp.com/newest.html';
			$newest = file_get_contents($url);  

			$newest = json_decode($newest,true);
			
			
			if($data['yiphp_version']!=$newest['author']){
				
				$data['newest'] = 1;
				
			}else{
				
				$data['newest'] = 0;
				
			}
			
			
		
		$this->assign('data',$data);
		
    
		$this->view();
    }
	
	/**
	 * 通过API借口获得更新信息
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 */
    public function Log(){
		
		action_log('addon_systeminfo_system_log'); 
		
		
		//页面配置
			$page = array(
				
				'title'=>'更新日志',
				'keywords'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'description'=>'YiPHP [ 我会的仅仅是偷懒！]',
				'author'=>'YiPHP',
				'robots' => 'all',
			
			);
			
			$this->assign('page',$page);
		
		$list = S('list');
		
		if(!$list){
			
			
			$url  = 'http://api.yiphp.com/log.html';
			$list = file_get_contents($url);  

			$list = json_decode($list,true);
		
			//缓存数据信息2个小时
			S('list',$list,7200);
	
		}
	
		
		$this->assign('list',$list);
		
        $this->view();
    }
	
	/**
	 * 实例化ThinkModel
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 */
	protected function _model(){
		
        return new \Think\Model();
		
    }
	
	/**
	 * 获得mysql版本信息
	 * @author 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
	 */
    private function _mysql_version(){
		
        $Model = self::_model();
        $version = $Model->query("select version() as ver");
        return $version[0]['ver'];
		
    }
	
	
	
}